package com.soar.recruitment.common.bll;

import com.soar.framework.app.FrameworkConstants;
import com.soar.framework.bll.SoarHttpRequest;
import java.util.Map;

public class SOARBaseHttpApi {

    public static volatile SOARBaseHttpApi instance;

    public static SOARBaseHttpApi getInstance() {
        if (instance == null) {
            synchronized(SOARBaseHttpApi.class) {
                if(instance == null) {
                    instance = new SOARBaseHttpApi();
                }
            }
        }
        return instance;
    }

    /**
     * 执行 Get 请求
     */
    public void doHttpGet(String url, Map<String, String> params, String tag, SOARHttpCallback SOARHttpCallback) {
        String postUrl = url.contains("http") ? url :FrameworkConstants.HOST + url;
        SoarHttpRequest.get()
                .url(postUrl)
                .params(params)
                .tag(tag)
                .build()
                .execute(SOARHttpCallback);
    }

    /**
     * 执行 Post 请求
     */
    public void doHttpPost(String url, Map<String, String> params, String tag, SOARHttpCallback SOARHttpCallback) {
        String postUrl = url.contains("http") ? url :FrameworkConstants.HOST + url;
        SoarHttpRequest.post()
                .url(postUrl)
                .params(params)
                .tag(tag)
                .build()
                .execute(SOARHttpCallback);
    }
}
